package com.yalu.service.data.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import com.yalu.dao.data.StoresPropertiesDao;
import com.yalu.entity.base.BaseEntity;
import com.yalu.entity.data.StoresProperties;
import com.yalu.service.base.impl.BaseServiceImpl;
import com.yalu.service.data.StoresPropertiesService;
import com.yalu.util.BaseUtil;

@Service
public class StoresPropertiesServiceImpl extends BaseServiceImpl<StoresProperties, String>
		implements StoresPropertiesService {

	@Resource
	private StoresPropertiesDao storesPropertiesDao;

	@Resource
	public void setBaseDao(StoresPropertiesDao storesPropertiesDao) {
		super.setBaseDao(storesPropertiesDao);
	}

	@Override
	public int[] save(List<BaseEntity> entityList) {
		int[] returnCounts = new int[2];
		int saveCount = 0;
		int updateCount = 0;
		String time = BaseUtil.getTime();
		for(BaseEntity baseEntity : entityList){
			StoresProperties entity = (StoresProperties)baseEntity;
			String key  = entity.getAttribute_id();
			StoresProperties temp = storesPropertiesDao.get(key);
			entity.setUpdatedt(time);
			BeanUtils.copyProperties(entity,temp, new String[] { "createdt",
					"createby", "updateby" });
			storesPropertiesDao.update(temp);
			updateCount++;
		}
		returnCounts[0]=saveCount;
		returnCounts[1]=updateCount;
		return returnCounts;
	}


}
